package com.cnhis.cloudhealth.clinical.util;

import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

import com.alibaba.fastjson.JSON;
import com.cnhis.cloudhealth.clinical.util.ExUtil;
import com.cnhis.cloudhealth.clinical.util.RunEx;
import com.cnhis.cloudhealth.commons.util.oplogutil.AsynUtil;
import com.google.common.collect.Maps;

public class FuturetaskExTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		FutureTask tsk= subtask();
		System.out.println("--");
		try {
			tsk.get();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			Throwable cause = e.getCause();			 
			if(cause.getMessage().contains("sub task err"))
			{
				RunEx re=(RunEx) cause;
				System.out.println(JSON.toJSONString( re.returnObj));
				System.out.println();
				
			}else
			ExUtil.throwExV2(e);
		}
	//	System.out.println("--");

	}

	public static FutureTask subtask() {
		FutureTask<Object> FutureTask_updateCviBdj=new FutureTask( new Callable<Object>() {

	  			@Override
	  			public Object call()   {				 
	  				System.out.println("--e in sub thread");
	  				
	  				if("a".equals("a"))
	  				{
	  					Map m=Maps.newConcurrentMap();m.put("k", "vv");
	  				 throw new RunEx("sub task err",m);
	  				 
	  				}
	  				return "err";
	  			}
	  		}) ;
	  		
	  		 AsynUtil.execMeth_Ays( FutureTask_updateCviBdj,"");
			return FutureTask_updateCviBdj;
	}

}
